package com.panopset.games.mocean;

import java.util.ArrayList;
import java.util.List;

public class MoceanSurface {

    private final List<MoceanSprite> sprites = new ArrayList<MoceanSprite>();

    Thread t;

    public synchronized List<MoceanSprite> getSprites(int width, int height) {
        if (sprites.isEmpty()) {
            MoceanSprite sprite = new MoceanSprite();
            sprite.center(width, height);
            sprites.add(sprite);
        } else {
            if (t == null) {
                t = new Thread(new Runnable() {

                    public void run() {
                        for (MoceanSprite s : sprites) {
                            MoceanSprite n = s.split();
                            if (n != null) {
                                sprites.add(n);
                            }
                        }
                        t = null;
                    }

                });
            }
        }
        return sprites;
    }


}
